﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/**
 * I think the following is a good example
 * another example can be found from wikipedia:
 * http://en.wikipedia.org/wiki/Proxy_pattern
 */

namespace DesignPatternsDemo.Proxy
{
    public interface IService
    {
        string ServiceMethod(string request);
    }

    public class SampleProxy : IService
    {
        private IService _remote;

        public SampleProxy()
        {
            Console.WriteLine("Constructing proxy ... "
                +"(Basically this is where the connection to the remote is happenning, " 
                + "and in real world the remote might obviously be on another machine and "
                + "should be accessed from the proxy through network infrastruture)");
            _remote = new Remote();
        }

        public string ServiceMethod(string request)
        {
            return _remote.ServiceMethod(request);
        }
    }

    public class Remote : IService
    {
        public string ServiceMethod(string request)
        {
            return "This is the service's response to \"" + request + "\"";
        }
    }
}
